# -*- coding: utf-8 -*-
from functools import reduce

def str2float(s):
    DIGITS = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'.':.}
    def getnum(i):
        return DIGITS[i]
    def fn(x,y):
        return x*10+y
    q = s.index('.')
    s1 = s[0:q]
    s2 = s[q+1:]
    return reduce(fn,map(getnum,s1))+reduce(fn,map(getnum,s2))*(10**(-len(s2)))
a = str2float('123.456')

print('str2float(\'123.456\' )=', a)

if abs(a - 123.456) < 0.001:

    print('测试成功！')

else:

    print('测试失败！')